package com.jiuyin.dianjing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.jiuyin.dianjing.R;
import com.jiuyin.dianjing.model.CommentModel;
import com.jiuyin.dianjing.util.DisplayUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ReplyAdapter extends RecyclerView.Adapter<ReplyAdapter.ViewHolder> {

    List<CommentModel.Reply> list = new ArrayList<>();
    Context mContext;

    public ReplyAdapter(List<CommentModel.Reply> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        View root = LayoutInflater.from(mContext).inflate(R.layout.item_reply, parent, false);
        return new ViewHolder(root);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ImageView ivHead = holder.itemView.findViewById(R.id.iv_head);
        CommentModel.Reply model = list.get(position);
        Glide.with(mContext)
                .load(model.s_header)
                .placeholder(R.mipmap.bga_pp_ic_holder_light)
                .override(DisplayUtil.dp2px(mContext, 40))
                .into(ivHead);
        holder.tvName.setText(model.s_nickname);
        holder.tvTime.setText(model.r_create_time);
        holder.tvContent.setText(model.r_content);
    }

    @Override
    public int getItemCount() {
        if (list == null){
            return 0;
        }
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_head)
        ImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_time)
        TextView tvTime;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
